Improve device-init grouped linear module with single grouped weight support #3224
Improve device-init grouped linear module with single grouped weight support #3224zhongbozhu wants to merge 9 commits into
Conversation
aa3b9d1 to
47ba66a
Compare
ff7eee2 to
a43f70f
Compare
6536aa1 to
1169d6e
Compare
| is_grad_enabled = torch.is_grad_enabled() | ||
| num_gemms = self.num_gemms | ||
|
|
||
| if FP8GlobalStateManager.fp8_graph_capturing(): |
There was a problem hiding this comment.
Note: this code block was deleted because it was duplicated
|
/te-ci pytorch |
Greptile SummaryThis PR enhances the device-init grouped linear module to support a single
Confidence Score: 5/5Safe to merge; all changed paths are well-tested and the core algorithmic changes are consistent with the existing design. The refactor is architecturally coherent: single-grouped-parameter routing is enforced by hard errors at both construction and forward time, the backward tensor unpacking correctly accounts for 1 vs N weight/bias arguments, and the CUDA kernel change properly scopes per-member scale bases. Test coverage is extensive. The three inline suggestions are style/annotation concerns that do not affect runtime behavior. No files require special attention beyond the two annotation-level suggestions in grouped_linear.py. Important Files Changed
Reviews (2): Last reviewed commit: "lint" | Re-trigger Greptile |
There was a problem hiding this comment.
The biggest change in this PR is that TE is abandoning any attempt to make single_grouped_weight=True a general feature. Things must be exactly right, or we crash. Given how delicate and experimental this feature has been, I'm not opposed.
The second change is that users must opt-in to access the grouped GEMM kernel. This is also reasonable, since it has alignment requirements for m_splits and it's helpful having a way for users to accept that stricter contract.
We are experiencing many test failures. Given that single_grouped_weight is no longer a general feature, I think it's reasonable we move the corresponding tests to test_grouped_linear.py and test_grouped_mlp.py.
| raise ValueError( | ||
| "The native grouped_tensor path requires CUDA m_splits. Pass a CUDA int64 " | ||
| "tensor, or select grouped_gemm_backend='legacy'." | ||
| ) |
There was a problem hiding this comment.
I get that the h2d memcpy is suboptimal, but it's trivially easy to handle. Erroring out seems excessively rigid.
| raise ValueError( | |
| "The native grouped_tensor path requires CUDA m_splits. Pass a CUDA int64 " | |
| "tensor, or select grouped_gemm_backend='legacy'." | |
| ) | |
| m_splits = m_splits.to(device=device) |
We need to handle the d2h case anyways when the user has specified grouped_gemm_backend="grouped_tensor", but it's not supported and we fallback to split-quantize.
There was a problem hiding this comment.
But if the alignment is not provided in the first place, converting it to a device tensor also wouldn't work right, I am okay with another alignment check before adding this H2D copy.
| EXPERIMENTAL and subject to change. Gated by the | ||
| ``NVTE_GROUPED_LINEAR_SINGLE_PARAM`` environment variable: if the env var | ||
| is not set this argument is forced to ``False`` with a warning. | ||
| grouped_gemm_backend : {"legacy", "grouped_tensor"}, default = None |
There was a problem hiding this comment.
These are misleading names.
- Legacy implies we are deprecating it, but in fact it is the default backend and it is the fallback when the grouped tensor impl is not supported.
- As mentioned in https://github.com/NVIDIA/TransformerEngine/pull/3224/changes#r3618050729, it's confusing that we might not actually perform the backend specified by the user. The user might put
grouped_gemm_backend="grouped_tensor"and we'll actually do split-quantize because the cuBLAS version is old or something.
Really, this is not a backend config. It's a hint where the user promises to provide m_splits with a certain alignment. I'd suggest changing this to a bool like enable_grouped_tensor_backend. Alternatively if we want to generalize in case we add more backends in the future, we could have a string like enabled_backends (enabled_backends="grouped_tensor,future_backend").
There was a problem hiding this comment.
and we'll actually do split-quantize because the cuBLAS version is old or something
Should we just raise error instead of silently doing this fallback? As a user, it's actually annoying to specify some optimization but it's not working because a fallback get triggered.
I am okay with changing the TE interface into a bool flag like enable_grouped_tensor_backend instead of a str.
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
for more information, see https://pre-commit.ci
3d37fd3 to
69b906f
Compare
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: